home *** CD-ROM | disk | FTP | other *** search
/ Champak 141 / (Vol 141) Oct 17 2011.iso / Games / Clueless.swf / scripts / DressupLevelInfo.as < prev    next >
Encoding:
Text File  |  2011-10-17  |  15.9 KB  |  506 lines

  1. package
  2. {
  3.    import flash.utils.*;
  4.    import flash.xml.XMLDocument;
  5.    import flash.xml.XMLNode;
  6.    import flash.xml.XMLNodeType;
  7.    
  8.    public class DressupLevelInfo
  9.    {
  10.        
  11.       
  12.       protected var _aAllowedClothes:Array;
  13.       
  14.       public var LevelCutscene:String;
  15.       
  16.       public var PowerUps:Array;
  17.       
  18.       public var UniqueThemes:Array;
  19.       
  20.       public var FiguresLeft:int = 10;
  21.       
  22.       public var LevelMusic:String;
  23.       
  24.       public var Package:PartTemplatePackage;
  25.       
  26.       public var LevelName:String;
  27.       
  28.       public var MillisecondsAllowed:Number = 95000;
  29.       
  30.       public var StartTime:int;
  31.       
  32.       public var LevelBackground:String;
  33.       
  34.       protected var _aPartners:Array;
  35.       
  36.       public var CurrentScore:int = 0;
  37.       
  38.       public var LevelPoseMultiplier:Number;
  39.       
  40.       public var DoubleDamage:Boolean = false;
  41.       
  42.       public var TotalFigures:int = 10;
  43.       
  44.       public var LevelTime:int;
  45.       
  46.       public var Partners:Array;
  47.       
  48.       public var PowerupRequiredScore:int = 2000;
  49.       
  50.       public var AvailablePowerups:Array;
  51.       
  52.       public var UsedItems:Array;
  53.       
  54.       public var CurrentTotalLetterGrade:int = 0;
  55.       
  56.       public var Themes:Array;
  57.       
  58.       public var bEndLevel:Boolean;
  59.       
  60.       public var TotalAccessories:int = 0;
  61.       
  62.       public var NumModels:int = 3;
  63.       
  64.       public var DoubleDamageTarget:String = null;
  65.       
  66.       public var LevelMinScore:int;
  67.       
  68.       protected var _aThemeLineup:Array;
  69.       
  70.       public var ModelLineup:Array;
  71.       
  72.       public var RemainingAccessories:Array;
  73.       
  74.       public var LevelPoses:Array;
  75.       
  76.       public var TopModels:Array;
  77.       
  78.       public function DressupLevelInfo(param1:String)
  79.       {
  80.          var _loc2_:DressupTheme = null;
  81.          var _loc3_:Database = null;
  82.          var _loc4_:XMLDocument = null;
  83.          var _loc5_:XMLNode = null;
  84.          var _loc6_:XMLNode = null;
  85.          var _loc7_:XMLNode = null;
  86.          var _loc8_:XMLNode = null;
  87.          var _loc9_:String = null;
  88.          var _loc10_:DressupTheme = null;
  89.          var _loc11_:XMLNode = null;
  90.          var _loc12_:XMLNode = null;
  91.          var _loc13_:XMLNode = null;
  92.          var _loc14_:Class = null;
  93.          var _loc15_:* = undefined;
  94.          var _loc16_:DressupTheme = null;
  95.          var _loc17_:Array = null;
  96.          var _loc18_:String = null;
  97.          var _loc19_:PartTemplate = null;
  98.          var _loc20_:String = null;
  99.          var _loc21_:Boolean = false;
  100.          var _loc22_:String = null;
  101.          var _loc23_:Array = null;
  102.          var _loc24_:int = 0;
  103.          var _loc25_:int = 0;
  104.          var _loc26_:DressupTheme = null;
  105.          var _loc27_:DressupTheme = null;
  106.          Themes = new Array();
  107.          UniqueThemes = new Array();
  108.          CurrentScore = 0;
  109.          CurrentTotalLetterGrade = 0;
  110.          FiguresLeft = 10;
  111.          TotalFigures = 10;
  112.          TotalAccessories = 0;
  113.          RemainingAccessories = new Array();
  114.          PowerUps = new Array();
  115.          AvailablePowerups = new Array();
  116.          Partners = new Array();
  117.          PowerupRequiredScore = 2000;
  118.          NumModels = 3;
  119.          LevelPoses = new Array();
  120.          MillisecondsAllowed = 95 * 1000;
  121.          DoubleDamage = false;
  122.          DoubleDamageTarget = null;
  123.          _aAllowedClothes = new Array();
  124.          _aThemeLineup = new Array();
  125.          _aPartners = new Array();
  126.          UsedItems = new Array();
  127.          TopModels = new Array();
  128.          ModelLineup = new Array();
  129.          super();
  130.          trace("Starting level : " + param1);
  131.          if(param1 == "Tutorial")
  132.          {
  133.             NumModels = 1;
  134.          }
  135.          _loc3_ = new Database();
  136.          Package = new PartTemplatePackage();
  137.          Package.copy(MainDocument.Package);
  138.          LevelName = param1;
  139.          _loc4_ = MainDocument.Levels.getDoc();
  140.          for each(_loc5_ in _loc4_.firstChild.childNodes)
  141.          {
  142.             if(_loc5_.nodeType == XMLNodeType.ELEMENT_NODE)
  143.             {
  144.                if(_loc5_.attributes["name"] == param1)
  145.                {
  146.                   FiguresLeft = parseInt(_loc5_.attributes["rounds"].toString());
  147.                   TotalFigures = FiguresLeft;
  148.                   LevelBackground = _loc5_.attributes["background"];
  149.                   if(_loc5_.attributes["score"] != undefined)
  150.                   {
  151.                      LevelMinScore = parseInt(_loc5_.attributes["score"].toString());
  152.                   }
  153.                   else
  154.                   {
  155.                      LevelMinScore = 40000;
  156.                   }
  157.                   if(_loc5_.attributes["cutscene"] != undefined)
  158.                   {
  159.                      LevelCutscene = _loc5_.attributes["cutscene"];
  160.                   }
  161.                   else
  162.                   {
  163.                      LevelCutscene = "";
  164.                   }
  165.                   if(_loc5_.attributes["final"] != undefined)
  166.                   {
  167.                      bEndLevel = true;
  168.                   }
  169.                   else
  170.                   {
  171.                      bEndLevel = false;
  172.                   }
  173.                   if(_loc5_.attributes["music"] != undefined)
  174.                   {
  175.                      LevelMusic = _loc5_.attributes["music"];
  176.                   }
  177.                   else
  178.                   {
  179.                      LevelMusic = "MenuMusic";
  180.                   }
  181.                   for each(_loc6_ in _loc5_.childNodes)
  182.                   {
  183.                      if(_loc6_.nodeType == XMLNodeType.ELEMENT_NODE)
  184.                      {
  185.                         if(_loc6_.localName == "Clothes")
  186.                         {
  187.                            for each(_loc7_ in _loc6_.childNodes)
  188.                            {
  189.                               if(_loc7_.nodeType == XMLNodeType.ELEMENT_NODE)
  190.                               {
  191.                                  _aAllowedClothes.push(_loc7_.attributes["name"]);
  192.                               }
  193.                            }
  194.                         }
  195.                         else if(_loc6_.localName == "Occasions")
  196.                         {
  197.                            for each(_loc8_ in _loc6_.childNodes)
  198.                            {
  199.                               if(_loc8_.nodeType == XMLNodeType.ELEMENT_NODE)
  200.                               {
  201.                                  _loc9_ = String(_loc8_.attributes["name"]);
  202.                                  _loc10_ = _loc3_.getTheme(_loc9_).clone();
  203.                                  if(_loc8_.attributes["partner"] != undefined)
  204.                                  {
  205.                                     _loc10_.ThemePartner = _loc3_.getPartner(_loc8_.attributes["partner"].toString());
  206.                                  }
  207.                                  Themes.push(_loc10_);
  208.                               }
  209.                            }
  210.                         }
  211.                         else if(_loc6_.localName == "Partners")
  212.                         {
  213.                            for each(_loc11_ in _loc6_.childNodes)
  214.                            {
  215.                               if(_loc11_.nodeType == XMLNodeType.ELEMENT_NODE)
  216.                               {
  217.                                  _aPartners.push(_loc3_.getPartner(_loc11_.attributes["name"]));
  218.                               }
  219.                            }
  220.                         }
  221.                         else if(_loc6_.localName == "AvailablePowerups")
  222.                         {
  223.                            for each(_loc12_ in _loc6_.childNodes)
  224.                            {
  225.                               if(_loc12_.nodeType == XMLNodeType.ELEMENT_NODE)
  226.                               {
  227.                                  AvailablePowerups.push(_loc12_.attributes["name"]);
  228.                               }
  229.                            }
  230.                         }
  231.                         else if(_loc6_.localName == "InitialPowerups")
  232.                         {
  233.                            for each(_loc13_ in _loc6_.childNodes)
  234.                            {
  235.                               if(_loc13_.nodeType == XMLNodeType.ELEMENT_NODE)
  236.                               {
  237.                                  _loc15_ = new (_loc14_ = Class(getDefinitionByName(_loc13_.attributes["name"])))();
  238.                                  addPowerup(_loc15_);
  239.                               }
  240.                            }
  241.                         }
  242.                      }
  243.                   }
  244.                }
  245.             }
  246.          }
  247.          if(_aAllowedClothes.length > 0)
  248.          {
  249.             for each(_loc16_ in Themes)
  250.             {
  251.                for each(_loc20_ in _loc16_.SampleParts)
  252.                {
  253.                   _loc21_ = false;
  254.                   for each(_loc22_ in _aAllowedClothes)
  255.                   {
  256.                      if(_loc22_ == _loc20_)
  257.                      {
  258.                         _loc21_ = true;
  259.                         break;
  260.                      }
  261.                   }
  262.                   if(!_loc21_)
  263.                   {
  264.                      _aAllowedClothes.push(_loc20_);
  265.                   }
  266.                }
  267.             }
  268.             _loc17_ = new Array();
  269.             for each(_loc18_ in _aAllowedClothes)
  270.             {
  271.                if(_loc18_.indexOf("_VER2") < 0)
  272.                {
  273.                   _loc17_.push(_loc18_);
  274.                }
  275.             }
  276.             Package.filter(_loc17_);
  277.             for each(_loc19_ in Package.Templates)
  278.             {
  279.                if(_loc19_.Category == "accessory")
  280.                {
  281.                   RemainingAccessories.push(_loc19_);
  282.                }
  283.             }
  284.             shuffleArray(RemainingAccessories);
  285.             TotalAccessories = RemainingAccessories.length;
  286.          }
  287.          UniqueThemes = Themes;
  288.          if(_aPartners.length > 0)
  289.          {
  290.             _loc23_ = new Array();
  291.             _loc24_ = 0;
  292.             while(_loc24_ < _aPartners.length)
  293.             {
  294.                _loc25_ = 0;
  295.                while(_loc25_ < Themes.length)
  296.                {
  297.                   _loc26_ = new DressupTheme();
  298.                   (_loc26_ = (_loc27_ = Themes[_loc25_] as DressupTheme).clone()).ThemePartner = _aPartners[_loc24_] as Partner;
  299.                   _loc23_.push(_loc26_);
  300.                   _loc25_++;
  301.                }
  302.                _loc24_++;
  303.             }
  304.             Themes = _loc23_;
  305.          }
  306.          _aThemeLineup = createSelection(Themes,FiguresLeft);
  307.          shuffleArray(_aThemeLineup);
  308.          PowerupRequiredScore = 500;
  309.          TopModels.push(new TopModel());
  310.          TopModels.push(new TopModel());
  311.          TopModels.push(new TopModel());
  312.          TopModels.push(new TopModel());
  313.          setupModelLineup();
  314.       }
  315.       
  316.       public static function createSelection(param1:Array, param2:int) : Array
  317.       {
  318.          var _loc3_:Array = null;
  319.          _loc3_ = expandArray(param1,param2);
  320.          shuffleArray(_loc3_);
  321.          return _loc3_;
  322.       }
  323.       
  324.       public static function shuffleArray(param1:Array) : void
  325.       {
  326.          var _loc2_:Object = null;
  327.          var _loc3_:int = 0;
  328.          var _loc4_:int = 0;
  329.          _loc3_ = 0;
  330.          while(_loc3_ < param1.length)
  331.          {
  332.             _loc4_ = Math.random() * param1.length;
  333.             _loc2_ = param1[_loc3_];
  334.             param1[_loc3_] = param1[_loc4_];
  335.             param1[_loc4_] = _loc2_;
  336.             _loc3_++;
  337.          }
  338.       }
  339.       
  340.       public static function expandArray(param1:Array, param2:int) : Array
  341.       {
  342.          var _loc3_:int = 0;
  343.          var _loc4_:Array = null;
  344.          _loc4_ = new Array();
  345.          _loc3_ = 0;
  346.          while(_loc3_ < param2)
  347.          {
  348.             _loc4_.push(param1[_loc3_ % param1.length]);
  349.             _loc3_++;
  350.          }
  351.          return _loc4_;
  352.       }
  353.       
  354.       public function updatePowerups() : void
  355.       {
  356.          var _loc1_:Array = null;
  357.          var _loc2_:Powerup = null;
  358.          _loc1_ = new Array();
  359.          for each(_loc2_ in PowerUps)
  360.          {
  361.             if(_loc2_.Charges > 0)
  362.             {
  363.                _loc1_.push(_loc2_);
  364.             }
  365.          }
  366.          PowerUps = _loc1_;
  367.       }
  368.       
  369.       protected function addPowerup(param1:Powerup) : Boolean
  370.       {
  371.          var _loc2_:Boolean = false;
  372.          _loc2_ = false;
  373.          updatePowerups();
  374.          if(PowerUps.length < 5)
  375.          {
  376.             _loc2_ = true;
  377.             param1.init(this);
  378.             PowerUps.push(param1);
  379.          }
  380.          return _loc2_;
  381.       }
  382.       
  383.       public function getRandomTheme() : DressupTheme
  384.       {
  385.          var _loc1_:int = 0;
  386.          var _loc2_:DressupTheme = null;
  387.          if(_aThemeLineup.length > 0)
  388.          {
  389.             return _aThemeLineup.pop() as DressupTheme;
  390.          }
  391.          _loc1_ = Math.random() * Themes.length;
  392.          _loc2_ = Themes[_loc1_];
  393.          _loc1_ = Math.random() * _aPartners.length;
  394.          if(_aPartners.length > 0)
  395.          {
  396.             _loc2_.ThemePartner = _aPartners[_loc1_];
  397.          }
  398.          return _loc2_;
  399.       }
  400.       
  401.       public function getNextAccessories() : Array
  402.       {
  403.          var _loc1_:PartTemplate = null;
  404.          var _loc2_:Array = null;
  405.          trace("Total = " + TotalAccessories + " FiguresLeft = " + FiguresLeft + " Remaining = " + RemainingAccessories.length);
  406.          for each(_loc1_ in RemainingAccessories)
  407.          {
  408.             trace("          " + _loc1_.Name);
  409.          }
  410.          _loc2_ = new Array();
  411.          if(FiguresLeft > 0 && RemainingAccessories.length > 0)
  412.          {
  413.             if(TotalAccessories <= TotalFigures / FiguresLeft * RemainingAccessories.length)
  414.             {
  415.                _loc2_.push(RemainingAccessories.pop());
  416.             }
  417.          }
  418.          trace("Return = " + _loc2_.length);
  419.          return _loc2_;
  420.       }
  421.       
  422.       public function getLevelPartners() : Array
  423.       {
  424.          return _aPartners;
  425.       }
  426.       
  427.       public function awardPowerup(param1:int) : Powerup
  428.       {
  429.          var _loc2_:Powerup = null;
  430.          var _loc3_:int = 0;
  431.          var _loc4_:Class = null;
  432.          _loc2_ = null;
  433.          if(AvailablePowerups.length == 0)
  434.          {
  435.             return null;
  436.          }
  437.          if(param1 > PowerupRequiredScore && AvailablePowerups.length > 0)
  438.          {
  439.             _loc3_ = Math.random() * AvailablePowerups.length;
  440.             _loc2_ = new (_loc4_ = Class(getDefinitionByName(AvailablePowerups[_loc3_])))();
  441.             if(!addPowerup(_loc2_))
  442.             {
  443.                _loc2_ = null;
  444.             }
  445.          }
  446.          return _loc2_;
  447.       }
  448.       
  449.       public function getNextModel() : PartTemplate
  450.       {
  451.          if(ModelLineup.length > 0)
  452.          {
  453.             return ModelLineup.pop() as PartTemplate;
  454.          }
  455.          return null;
  456.       }
  457.       
  458.       public function getRankDiamonds() : int
  459.       {
  460.          if(CurrentScore > 10000)
  461.          {
  462.             return 5;
  463.          }
  464.          if(CurrentScore > 4000)
  465.          {
  466.             return 4;
  467.          }
  468.          if(CurrentScore > 2000)
  469.          {
  470.             return 3;
  471.          }
  472.          if(CurrentScore > 1000)
  473.          {
  474.             return 2;
  475.          }
  476.          if(CurrentScore > 500)
  477.          {
  478.             return 1;
  479.          }
  480.          return 0;
  481.       }
  482.       
  483.       internal function setupModelLineup() : void
  484.       {
  485.          var _loc1_:Array = null;
  486.          var _loc2_:int = 0;
  487.          var _loc3_:int = 0;
  488.          ModelLineup = new Array();
  489.          _loc1_ = MainDocument.Package.getAllTemplates("body");
  490.          _loc2_ = FiguresLeft;
  491.          _loc3_ = 0;
  492.          while(_loc2_ > 0)
  493.          {
  494.             ModelLineup.push(_loc1_[_loc3_]);
  495.             _loc3_++;
  496.             if(_loc3_ >= _loc1_.length)
  497.             {
  498.                _loc3_ = 0;
  499.             }
  500.             _loc2_--;
  501.          }
  502.          shuffleArray(ModelLineup);
  503.       }
  504.    }
  505. }
  506.